package com.woniu.defecttracking.controller.datas;


import com.woniu.defecttracking.commens.Result;
import com.woniu.defecttracking.dto.MenusDto;
import com.woniu.defecttracking.service.MenusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 倪西
 * @since 2021-12-31
 */
@RestController
@RequestMapping("/menus")
public class MenusController {

    @Autowired
    private MenusService menusService;

    /**
    * @作者: 倪西
    * @描述：ctroller层调用service层的findMenusByAccount方法获取集合返回给前端
    * @时间：2022/1/1 16:09
    * @参数：[id]
    * @返回：com.woniu.defecttracking.commens.Result
    **/
    @GetMapping("/findMenusByAccount/{id}")
    public Result findMenusByAccount(@PathVariable("id") Integer id){
        List<MenusDto> menusDtos = menusService.findMenusByAccount(id);
        return Result.getInstance(menusDtos);
    }

    /**
    * @作者: 倪西
    * @描述：查询所有的菜单
    * @时间：2022/1/7 21:50
    * @参数：[]
    * @返回：com.woniu.defecttracking.commens.Result
    **/
    @PostMapping("/findMenus")
    public Result findMenus(){
        List<MenusDto> menusDtos = menusService.findMenus();
        return Result.getInstance(menusDtos);
    }

    /**
    * @作者: 倪西
    * @描述：查询账号所拥有的菜单信息
    * @时间：2022/1/7 21:50
    * @参数：[id]
    * @返回：com.woniu.defecttracking.commens.Result
    **/
    @GetMapping("/findMenusByRuleId/{id}")
    public Result findMenusByRuleId(@PathVariable("id") Integer id){
        List<Integer> menusIds = menusService.findMenusByRuleId(id);
        return Result.getInstance(menusIds);
    }
}

